package com.ruoyi.common.core.enums;

import java.util.stream.Stream;

/**
 * @Description: 是否
 */
public enum YesNoEnum {

    YES("Y", 1,"是"),
    NO("N", 0, "否");

    private final String code;
    private final Integer num;
    private final String name;

    YesNoEnum(String code, Integer num, String name) {
        this.code = code;
        this.num = num;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public Integer getNum() {
        return num;
    }

    public String getName() {
        return name;
    }

    public static String getNameByCode(String code) {
        for (YesNoEnum item : YesNoEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getName();
            }
        }
        return null;
    }

    public static String getCodeByName(String name) {
        for (YesNoEnum item : YesNoEnum.values()) {
            if (item.getName().equals(name)) {
                return item.code;
            }
        }
        return null;
    }


    public static String getNameByNum(Integer num) {

         return Stream.of(YesNoEnum.values()).filter(e->e.getNum().equals(num)).findFirst().map(YesNoEnum::getName).orElse("");
    }
}
